﻿'***************************************************************************\
' Module Name: ConsoleApplication.vb
' Project: SetDefaultAudioEndpoint http://sdae.codeplex.com/
' Copyright 2011 by jeff
' 
' This source is subject to the GNU General Public License version 2 (GPLv2).
' See http://www.gnu.org/licenses/gpl-2.0.html.
' All other rights reserved.
' 
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'***************************************************************************/

Imports SetDefaultAudioEndpoint.CommandLineParser

Module ConsoleApplication
  Sub Main()

    Dim parser As New CommandLineParser()
    Dim options As ExecutionOptions = parser.Parse(My.Application.CommandLineArgs.ToArray)

    Select Case parser.Result
      Case CommandLineParserResult.OK
        Dim dispatcher As New ExecutionOptionsDispatcher
        Try
          dispatcher.Dispatch(options)
        Catch ex As WindowsSoundException
          ConsoleApplication.WriteConsoleError(ex.ToString)
        End Try
      Case CommandLineParserResult.Usage
        Console.WriteLine(CommandLineParser.Usage)
      Case CommandLineParserResult.Fail
        ConsoleApplication.WriteConsoleError(parser.ParseError)
      Case Else
        Throw New NotImplementedException()
    End Select
  End Sub

  Private Sub WriteConsoleSuccess(ByVal message As String, ByVal device As String)
    Console.WriteLine(String.Format(Globalization.CultureInfo.CurrentCulture, "The default audio {0} device was set to '{1}'.", message, device))
    Debug.WriteLine(String.Format(Globalization.CultureInfo.CurrentCulture, "The default audio {0} device was set to '{1}'.", message, device))
  End Sub

  Private Sub WriteConsoleError(ByVal message As String)
    Console.Error.WriteLine()
    Console.Error.WriteLine(message)
    Debug.WriteLine(message)
  End Sub

End Module
